<?php
/**
 * Created by PhpStorm.
 * User: lzy
 * Date: 2019/5/21
 * Time: 16:58
 */

namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IArticle;
use App\Util\ResultsVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class ArticleController extends Controller
{
    public $articleService;

    public function __construct(IArticle $articleService)
    {
        $this->articleService = $articleService;
    }

    public function page(Request $request)
    {
        $search = [];
        $size = 10;
        $search['typeId'] = 1;
        $data = $this->articleService->paginate($search,$request->get('page',1),$size);
        return response()->json(new ResultsVo(['data'=>$data['results']],['id','title','cover','date','click'],[]));
    }

    public function state($id, $state)
    {
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function show($id)
    {
        $data = $this->articleService->byId($id);
        return response()->json(new ResultsVo(['data'=>$data->toArray()],['title','content'],[]));
    }

    public function agreement()
    {
        $search = [];
        $search['id'] = 98;
        //$search['typeId'] = 5;
        $data = $this->articleService->agreement($search);
        return response()->json(new ResultsVo(['data'=>$data->toArray()],['title','content'],[]));
    }
}